<template>
  <div>
    <h1>转发</h1>
    <el-button type="primary" @click="openAdd">转发文章</el-button>
    <el-table
      :data="specialist"
      style="width: 100%">
      <el-table-column
        prop="sensitiveId"
        label="sensitiveId"
        width="180">
      </el-table-column>
      <el-table-column
        prop="sensitiveName"
        label="sensitiveName"
        width="180">
      </el-table-column>
      <el-table-column
        label="操作"
        width="260">
        <template slot-scope="scope" >
          <el-button type="primary" @click="removeTbBbsSensitive(scope.row.sensitiveId)">删除</el-button>
          <el-button type="primary" @click="updateTbBbsSensitive(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="添加/修改明感词"
      :visible.sync="dialogVisible"
      width="60%">
      <el-form ref="form" :model="expert" label-width="80px">
        <el-form-item label="敏感词">
          <el-input v-model="expert.sensitiveName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="insertTbBbsSensitive">立即创建</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <div class="block">
      <el-pagination
        :current-page="pagenum"
        :page-sizes="[2,3,1]"
        :page-size="pagenum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>

  </div>
</template>
<script>
  import {findTbBbsSensitiveall,removeTbBbsSensitive,insertTbBbsSensitive} from '@/api/bbs'
  export default {
    data(){
      return{
        specialist:[],
        dialogVisible:false,
        expert:{},
          pagenum :1,
          pagesize :3,
          total :0
      }
    },
    mounted(){
      this.findTbBbsSensitiveall();
    },
    methods: {
      updateTbBbsSensitive(row){
        this.expert=row
        this.dialogVisible=true
      },
      insertTbBbsSensitive(){
        insertTbBbsSensitive(this.expert).then(res=>{
          alert(res.msg)
          this.expert={}
          this.dialogVisible=false
          this.findTbBbsSensitiveall()
        })
      },
      findTbBbsSensitiveall(){
        findTbBbsSensitiveall(this.pagesize,this.pagenum).then(res=>{
          console.log(res.data)
          this.specialist=res.data;
          this.total=res.total;
        })
      },
      removeTbBbsSensitive(sensitiveId){
        removeTbBbsSensitive(sensitiveId).then(res=>{
          alert(res.msg),
            location.reload();
        })
      },
      openAdd(){
        this.dialogVisible=true
      },
      handleSizeChange(val) {
        this.pagesize=val;
        this.findTbBbsSensitiveall();
      },
      handleCurrentChange(val) {
        this.pagenum=val;
        this.findTbBbsSensitiveall();
      }
    }
  }
</script>
<style>

</style>
